<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				审批
				<a-icon @click="closeFunction" :style="{ fontSize: '20px', float: 'right', margin: '10px' }"
					type="close-circle" />
			</p>
			<div class="main" id="new_message">
				<a-form-model ref="ruleForm" :model="form" :rules="rules" style="margin-top:50px;">
					<!-- <a-form-model-item v-if="isShow" label="完结附件">
						<a-list class="fileListArea" size="small" bordered :dataSource="oldList" v-if="oldList.length">
							<a-list-item slot="renderItem" slot-scope="item, index" style="display: flex;">
								<div style="flex: 1;">
									<div style="width: 96%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{{ item.FileName }}</div>
								</div>
								<a-icon type="delete" @click="deleteFile(item, 1)" style="height: 12px;vertical-align: top;margin-top: 4px;margin-right:12px;cursor: pointer;"></a-icon>
								<a-icon type="download" @click="downloadFile(item, 1)" style="height: 12px;vertical-align: top;margin-top: 4px;margin-right:12px;cursor: pointer;"></a-icon>
							</a-list-item>
						</a-list>
					</a-form-model-item> -->
					<a-form-model-item label="是否通过" prop="state">
						<a-radio-group name="radioGroup" v-model="form.state">
							<a-radio :value="2">通过</a-radio>
							<a-radio :value="3">驳回</a-radio>
						</a-radio-group>
					</a-form-model-item>
					<a-form-model-item label="内容" prop="comment">
						<a-input type="textarea" v-model="form.comment" />
					</a-form-model-item>
					<a-form-model-item label="" class="fixed-bottom">
						<a-button type="primary" @click="handleSubmit">提交</a-button>
						<a-button style="margin-left: 10px;" @click="closeFunction">取消</a-button>
					</a-form-model-item>
				</a-form-model>
			</div>
		</div>
	</div>
</template>

<script>
	import Cache from '@/utils/cache';
	import {
		ManageActivityEvaluationDoExam,
		GetActivityFileList,
		DeleteActivityFile,
		ManageAssistantTransferApplyDoGetAssistantList
	} from '@/api/follow';
	export default {
		props: {
			text: Object,
			isShow: Boolean
		},
		watch: {
			text: function(text) {
				//this.getList();
			}
		},
		data() {
			return {
				fetching:false,
				userList: [],
				oldList: [],
				formLayout: 'horizontal',
				form: this.$form.createForm(this, {
					name: 'coordinated'
				}),
				DepartmenDropdowntList: [],
				form: {
					state: 2,
					comment: '',
					UserNo: []
				},
				rules: {
					state: [{
						required: true,
						message: '请选择是否通过',
						trigger: 'change'
					}]
				},
				requestUrl: this.global.requestUrl,
				token: Cache.get('token'),
			};
		},
		created() {
			
		},
		methods: {
			filterOption(input, option) {
				return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
			},
			async fetchUser(value) {
				console.log(value)
				this.fetching = true
				let myReg = /^[^a-zA-Z]+$/
				if (value && myReg.test(value) && value.length > 1) {
					let data = {}
					data.userNo = value
					data.applyID=this.text.ID
					let res = {}
					res = await ManageAssistantTransferApplyDoGetAssistantList(data)
					this.fetching = false
					this.userList = res.data.data
				}


			},
			async getList() {
				let res = await GetActivityFileList({
					activityID: this.text.ActivityID,
					type: 2
				});
				let res1 = await GetActivityFileList({
					activityID: this.text.ID,
					type: 2
				});
				this.oldList = res.data.data.length == 0 ? res1.data.data : res.data.data;
			},
			async deleteFile(item) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定删除该附件吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let res = await DeleteActivityFile({
							id: item.ID
						});
						if (res.data.code == 0) {
							that.oldList.splice(that.oldList.findIndex(m => m.ID === item.ID), 1);
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			async downloadFile(item) {
				let hrefUrl = this.requestUrl + 'Manage/ActivityFile/DownFile?userToken=' + encodeURIComponent(this
					.token) + '&id=' + item.ID;
				window.open(hrefUrl, '_blank');
			},
			closeFunction(data) {
				this.$emit('closeFun', data);
				this.$refs.ruleForm.resetFields();
			},
			handleSubmit(e) {
				console.log('sss');
				this.$refs.ruleForm.validate(async valid => {
					if (valid) {
						let data = this.form;
						data.id = this.text.ID;
						let res = {};
						res = await ManageActivityEvaluationDoExam(data);
						if (res.data.code === 0) {
							this.$message.success(res.data.msg);
							this.closeFunction('1');
						} else {
							this.$message.error(res.data.msg);
						}
					} else {
						return false;
					}
				});
			}
		}
	};
</script>

<style lang="less" scoped>
	.aid {
		position: fixed;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.5);
		top: 0px;
		left: 0px;
		z-index: 999;
	}

	.base {
		position: absolute;
		width: 600px;
		height: 540px;
		background: #fff;
		left: 50%;
		margin-left: -300px;
		top: 50%;
		margin-top: -270px;
		overflow-y: auto;
	}

	.main {
		height: 90%;
		overflow-y: scroll;
	}

	/deep/.ant-form-item {
		margin: 20px 50px;
		display: flex;
	}

	/deep/.ant-form-item-label {
		width: 100px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	/deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	.base p {
		padding: 10px 0 0 10px;
	}

	.subnav {
		margin-left: 60px;
		height: 46px;
		display: flex;
	}

	.subnav p {
		width: 100px;
		text-align: right;
	}

	.subnav input {
		width: 300px;
		height: 30px;
		border: 1px solid #dad9dc;
		margin-left: 20px;
	}

	.ant-form-item {
		margin-bottom: 10px;
	}

	.btn2 {
		display: -moz-box;
		-moz-box-pack: center;
		-moz-box-align: center;

		/* Safari、Opera 以及 Chrome */
		display: -webkit-box;
		-webkit-box-pack: center;
		-webkit-box-align: center;

		/* W3C */
		display: flex;
		box-pack: center;
		box-align: center;
		width: 137px;
		height: 35px;
		border-radius: 3px;
		outline: none;
		border: none;
		margin: 20px auto;
		color: #fff;
	}

	.fixed-top {
		width: inherit;
		position: absolute;
		line-height: 30px;
		top: 0px;
		background-color: white;
		z-index: 999;
	}

	.fixed-bottom {
		width: 164px;
		left: 50%;
		bottom: 0px;
		margin: 0px 0px 0px -82px !important;
		position: absolute;
		background-color: white;
		z-index: 999;
	}

	/deep/.ant-form {
		margin-top: 50px;
		padding-bottom: 50px;
	}
</style>
